<template>
	<el-container>
		<el-header class='x-header'>
			<b class="title">{{ page_info.title }}</b>
			<el-button v-if="$route.query.callback_url" size="mini" icon="el-icon-back" @click="g_page.funcBack">
				返回
			</el-button>
			<el-button size="mini" icon="el-icon-refresh" @click="g_page.funcReload()">刷新</el-button>
		</el-header>
		<el-main class='x-main'>
			<el-form :inline="true" :model="form_q" size="mini">
				<el-form-item label="转赠用户">
					<el-input v-model="form_q.compOpenid" placeholder="openid"></el-input>
				</el-form-item>
				<el-form-item label="类型">
					<el-select filterable clearable v-model="form_q.compType">
						<el-option
							v-for="(val,key) in page_info.type"
							:key="`${key}`"
							:value="`${key}`"
							:label="val">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="g_page.funcSearch">搜索</el-button>
				</el-form-item>
			</el-form>
			<div class="table-wrap">
				<el-table stripe ref="multipleTable" tooltip-effect="dark" @selection-change="g_page.funcTableSelectionChange"
						  :data="list_data">
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="ID">
						<template slot-scope="data">
							<div>{{data.row.id}}</div>
						</template>
					</el-table-column>
					<el-table-column label="用户">
						<template slot-scope="data">
							<div>{{data.row.wxuser_nickname}}</div>
							<div>{{data.row.wxuser_openid}}</div>
						</template>
					</el-table-column>
					<el-table-column label="类型">
						<template slot-scope="data">
							<div>{{data.row.type}}</div>
						</template>
					</el-table-column>
					<el-table-column label="寄语">
						<template slot-scope="data">
							<el-input type="textarea" v-model="data.row.pgpke_content" :rows="3"></el-input>
						</template>
					</el-table-column>
					<el-table-column label="有效期" width="150">
						<template slot-scope="data">
							<div>{{data.row.pgpke_begin_date}}</div>
							<div>{{data.row.pgpke_expire_date}}</div>
							<div v-if="data.row.left_s<=0" style="color: red;">已过期</div>
						</template>
					</el-table-column>
					<el-table-column label="领取状态">
						<template slot-scope="data">
							{{ data.row.get_state }}
						</template>
					</el-table-column>
					<el-table-column label="数量">
						<template slot-scope="data">
							<div>
								{{data.row.pgpke_get_count}} / {{data.row.pgpke_count}}
							</div>
						</template>
					</el-table-column>
					<el-table-column label="创建时间" width="150">
						<template slot-scope="data">
							<div>{{data.row.pgpke_create_date}}</div>
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作">
						<template slot-scope="data">
							<el-button type="text" @click="g_page.funcRedirectEdit(`prize__give_get__list?pid=${data.row.id}`)" size="mini">
								领取情况
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-main>
		<!---->
		<!---->
		<!-- 分页 -->
		<el-footer v-if="page_show" class="x-page">
			<el-pagination class="paging" background layout="total, sizes, prev, pager, next, jumper"
						   @current-change="g_page.funcPageChange" :page-sizes="[page_size]"
						   :current-page="page_index" :page-size="page_size" :total="page_total">
			</el-pagination>
		</el-footer>
		<!---->
		<!---->
		<!-- 弹框 -->
		<el-dialog :title="form.app_idx+'配置'" :visible.sync="form_dialog_visible" width="70%">
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-form-item label="入口链接" v-if="!g_page.funcIsAdminAdd()">
					<el-input :disabled="true" v-model="form.oauth_url"/>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="g_page.funcBack" size="mini">取消</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
			</div>
		</el-dialog>
		<!---->
		<!---->
		<!---->
	</el-container>
</template>


<script>
	import ExprotExcel from '@/components/ExprotExcel'
	import {
		MessageBox, Message
	} from 'element-ui'

	export default {
		components: {
			ExprotExcel
		},
		data() {
			let page_data = { super_uid: '' }
			page_data = this.g_cc.funcGetInitData(page_data)
			return page_data
		},
		mounted() {
			console.log('mounted')
			//
			this.g_page.funcSetVue(this)
			// 应用ID
			this.g_page.funcSetApiUrlList('/xadmin/prize/prize__give__list')
			// this.g_page.funcSetApiUrlDel('/xadmin/prize/prize__give__list/del')
			//页码
			this.g_page.funcSetPageSize(20)
			//搜索
			this.form_q = {
				'compKw': ''
			}
			this.g_page.funcGetList()
			//
			this.form_rules = {
				acc_uidX: [
					{
						required: true,
						message: '必填',
						trigger: 'blur'
					}
				]
			}
			//
		},
		methods: {
			funcSaveBefore(data) {
				console.log('funcSaveBefore', data)

				// data.reply_pic = this.g_page.funcImgArrToStr(data.reply_pic_imgs)

				return data
			},
			//发货
			funcDeliver(row) {
				let page = this
				MessageBox.prompt('物流单号', '发货操作', {
					confirmButtonText: '发货',
					cancelButtonText: '取消',
					inputErrorMessage: '请输入物流单号',
					inputValue: row.prize_deliver_no
				}).then(({ value }) => {
					let deliver_no = value
					if (!deliver_no) {
						this.g_cc.func_alert('请输入物流单号', 'error')
						return
					}
					page.g_cc.func_axios({
						url: '/xadmin/prize/prize__item__list/funcDeliver',
						data: {
							deliver_no: deliver_no,
							ids: row.id
						},
						loading: false,
						success: (res) => {
							//
							if (res.data.errcode == 0) {
								page.g_cc.func_alert(res.data.errmsg, 'success', function() {
									page.g_page.funcGetList()
								})
							} else {
								page.g_cc.func_alert(res.data.errmsg, 'error')
							}
						}
						//
					})
				}).catch(() => {
					console.log('取消')
				})
			}
			////////////////////
		}
	}
</script>
